package com.yaj.mesif.config;

import com.yaj.mesif.quartz.IFO1004;
import com.yaj.mesif.quartz.IFO1005;
import org.quartz.*;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @ClassName QuartzConfig
 * @Description Quartz定时任务配置类
 * @date 2021/8/24 14:16
 * @Version 1.0
 */
@Configuration
public class QuartzConfig {

    @Value("${quartz.timeinterval.ifo1004}")
    String IFO1004_TIMEINTERVAL;

    @Value("${quartz.timeinterval.ifo1005}")
    String IFO1005_TIMEINTERVAL;

    @Bean
    public JobDetail syncIFO1004JobDetail(){
        return JobBuilder.newJob(IFO1004.class).withIdentity("IFO1004").storeDurably().build();
    }

    @Bean
    public JobDetail syncIFO1005JobDetail(){
        return JobBuilder.newJob(IFO1005.class).withIdentity("IFO1005").storeDurably().build();
    }

    @Bean
    public Trigger syncIFO1004JobTrigger(){
        //几秒执行一次
        SimpleScheduleBuilder scheduleBuilder = SimpleScheduleBuilder.simpleSchedule()
                .withIntervalInSeconds(Integer.parseInt(IFO1004_TIMEINTERVAL))
                .repeatForever();
        return TriggerBuilder.newTrigger().forJob(syncIFO1004JobDetail())
                .withIdentity("IFO1004Task")
                .withSchedule(scheduleBuilder)
                .build();
    }

    @Bean
    public Trigger syncIFO1005JobTrigger(){
        //几秒执行一次
        SimpleScheduleBuilder scheduleBuilder = SimpleScheduleBuilder.simpleSchedule()
                .withIntervalInSeconds(Integer.parseInt(IFO1005_TIMEINTERVAL))
                .repeatForever();


        return TriggerBuilder.newTrigger().forJob(syncIFO1005JobDetail())
                .withIdentity("IFO1005Task")
                .withSchedule(scheduleBuilder)
                .build();
    }
}
